

<template>
    <rm-layout-top splitcolor="white" :splitwidth=5 :fixsize=35 :canDrag=false>
        <template v-slot:fix>
            <div style="height:35px;border:1px solid #CCC;padding:4px">
                <el-row>
                    <el-col :span="6">
                        <div class="grid-content bg-purple"> <span class="remind_class">仪器危急值消息提醒</span></div>
                    </el-col>
                    <el-col :span="8">
                        <div class="grid-content bg-purple">
                            <div style="float:left;width:140px;line-height: 25px;color:blue">确认人：{{remindobj.confirmusername}}</div>
                            <div style="float:left;line-height: 25px;color:blue">
                                <el-checkbox v-model="remindobj.chkremind" true-label="1" false-label="0" @change="chkremindChange">记住</el-checkbox>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="10">
                        <div class="grid-content bg-purple-light">
                            <el-button style="width:72px" @click.native="btnRefresh">刷新</el-button>
                            <el-button style="width:72px" @click.native="btnSelectll('chk')">全选</el-button>
                            <el-button style="width:72px" @click.native="btnSelectll('clr')">清除全选</el-button>
                            <el-button style="width:72px" @click.native="btnConfirm">确认</el-button>
                            <el-button style="width:72px" @click.native="btnClose">退出</el-button>
                        </div>
                    </el-col>

                </el-row>
            </div>
        </template>
        <div style="height:100%">
            <vxe-table show-overflow ref="xTable" :data.sync="labalertdata" height="auto" width="100%" border size="mini" :select-config="{ reserve: true }" show-header-overflow resizable header-align="center" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }" key="1" :row-class-name="rowclassname" class="mytable-style" @current-change="currentChangeEvent" :loading="loading">
                <!--:span-method="rowspanMethod"-->
                <vxe-table-column field="rptunitid" title="报告单元" width="120">
                    <template v-slot="{row}">
                        <div>{{row.rptunitname}}&nbsp;&nbsp;[{{row.rptunitid}}]</div>
                    </template>
                </vxe-table-column>
                <vxe-table-column field="sampledate" title="标本日期" width="90" :formatter="['toDateString', 'yyyy-MM-dd']" align="center"></vxe-table-column>
                <vxe-table-column field="sampleno" title="标本号" width="70"></vxe-table-column>
                <vxe-table-column field="rpt_itemcode" title="检验项目" width="150">
                    <template v-slot="{row}">
                        <div>{{row.rpt_itemname}}&nbsp;&nbsp;[{{row.rpt_itemcode}}]</div>
                    </template>
                </vxe-table-column>
                <vxe-table-column field="result_str" title="检验结果" width="70" align="center"></vxe-table-column>
                <vxe-table-column field="alertrules" title="违反规则" width="100"></vxe-table-column>
                <vxe-table-column field="chkflag" title="选择" width="50" align="center">
                    <template v-slot="{row}">
                        <el-checkbox true-label="1" false-label="0" v-model="row.chkflag" @change="chkflagpartchange(row)"></el-checkbox>
                    </template>
                </vxe-table-column>
                <vxe-table-column field="pat_name" title="姓名" width="70"></vxe-table-column>
                <vxe-table-column field="pat_sex" title="性别" width="50" align="center">
                    <template v-slot="{row}">
                        <div>{{!!row.pat_sex?(row.pat_sex=='1'?'男':'女'):"未知"}}</div>
                    </template>
                </vxe-table-column>
                <vxe-table-column field="pat_agestr" title="年龄" width="50" align="center"></vxe-table-column>
                <vxe-table-column field="pat_no" title="病历号" width="80"></vxe-table-column>
                <vxe-table-column field="req_deptname" title="申请科室" width="100"></vxe-table-column>
                <vxe-table-column field="req_wardname" title="病区" width="100"></vxe-table-column>
                <vxe-table-column field="req_bedno" title="床号" width="70" align="center"></vxe-table-column>
                <vxe-table-column field="req_docno" title="申请医生" width="70" align="center"></vxe-table-column>
                <vxe-table-column field="result_dt" title="结果时间" width="120"></vxe-table-column>
                <vxe-table-column field="createdt" title="生成时间" width="120"></vxe-table-column>
                <vxe-table-column field="instrid" title="仪器" width="150">
                    <template v-slot="{row}">
                        <div>{{row.instrname}}&nbsp;&nbsp;[{{row.instrid}}]</div>
                    </template>
                </vxe-table-column>
                <template v-slot:fix>
                    <div style="font-size:17px;padding-top:3px;background-color:#fff;text-align:center;font-weight:bold;color:blue">共 {{datacnt}} 条</div>
                </template>
            </vxe-table>
        </div>

    </rm-layout-top>

</template>

<script type="text/javascript">
export default {
    name: "rm_devalertinfo",
    props: {
        tabledata: { type: Array },
        params: { type: Object },
    },
    data() {
        return {
            labalertdata: this.tabledata,
            labobj: { formobj: {}, tableobj: [], plankey: 0 },
            loading: false,
            remindobj: { confirmuserid: "", confirmusername: "", chkremind: "0", isfirstconfirm: false },
        };
    },
    created() {
        let confirmobj = localStorage.getItem("rm_instrnoalertinfo_confirmuser");
        if (!!(localStorage.rm_instrnoalertinfo_confirmuser&&JSON.parse(localStorage.rm_instrnoalertinfo_confirmuser))) this.remindobj =JSON.parse(confirmobj);
    },
    computed: {
        datacnt() {
            return this.labalertdata.length;
        },
    },
    watch: {},
    mounted() {},
    methods: {
        //获取自动提醒弹窗的选中行
        currentChangeEvent({ row, column }) {},
        //记住确认人事件
        chkremindChange() {
            if (this.remindobj.chkremind == "0") {
                this.remindobj.confirmuserid = "";
                this.remindobj.confirmusername = "";
                this.remindobj.isfirstconfirm = false;
                localStorage.removeItem("rm_instrnoalertinfo_confirmuser");
            } else {
                this.confirmuserStorage();
            }
        },
        //自动提醒弹窗列表的颜色
        rowclassname({ row, column }) {
            if (row.chkflag == "1") {
                return "row-pink";
            }
        },
        //全选与全不选
        btnSelectll(flag) {
            if (flag == "chk") {
                this.labalertdata.forEach((item) => {
                    item.chkflag = "1";
                });
            } else {
                this.labalertdata.forEach((item) => {
                    item.chkflag = "0";
                });
            }
        },
        //部分选择
        chkflagpartchange(row) {
            if (row.chkflag == "1") {
                let data = this.labalertdata.filter((item) => item.rptunitid == row.rptunitid && item.sampledate == row.sampledate && item.sampleno == row.sampleno);
                if (data.length > 0) {
                    data.forEach((item) => {
                        item.chkflag = "1";
                    });
                }
            } else {
                row.chkflag = "0";
            }
        },
        confirmuserStorage() {
            if (this.remindobj.chkremind == "1") {
                if (!!this.remindobj.confirmuserid && !!this.remindobj.confirmusername) localStorage.setItem("rm_instrnoalertinfo_confirmuser",JSON.stringify(this.remindobj));
            }
        },
        //确认
        btnConfirm() {
            let data = this.labalertdata.filter((item) => item.chkflag == "1");
            if (data.length > 0) {
                if (!this.remindobj.isfirstconfirm && !this.remindobj.confirmusername) {
                    this.$rm_Login({
                        type: "请输入工号和密码",
                        btn: {
                            confirmBtnText: "确定",
                            cancelBtnText: "取消",
                        },
                    })
                        .then((res) => {
                            if (res.flag == "1") {
                                this.remindobj.isfirstconfirm = true;
                                this.remindobj.confirmuserid = res.userid;
                                this.remindobj.confirmusername = res.username;
                                this.confirmuserStorage();
                                this.saveInstrAlert(data);
                            }
                        })
                        .catch((e) => {
                            this.$pub.message(this, "已取消登录", "warning");
                        });
                } else {
                    this.saveInstrAlert(data);
                }
            } else {
                this.$alert("请至少选择一条记录进行确认！", "提示");
            }
        },//确认
        saveInstrAlert(data) {
            this.$tool
                .request({
                    url: "ucent/handlemsg",
                    method: "post",
                    data: {
                        action: "saveInstrAlert",
                        saveinfo: data,
                        transuser: this.remindobj.confirmuserid,
                    },
                })
                .then((res) => {
                    if (res.errcode == "1") {
                        this.$pub.message(this, "已成功处理" + data.length + "条仪器危急值！", "success");
                        this.btnRefresh();
                    } else {
                        this.$alert(res.errmsg, "提示");
                    }
                })
                .catch((e) => {
                    this.$alert(e, "提示");
                });
        },
        //刷新仪器危急值
        btnRefresh() {
            this.loading = true;
            this.$tool
                .request({
                    url: "ucent/alertmsg",
                    method: "post",
                    data: {
                        //action: "labInstrAlert",
                        params: this.params.paramlist,
                    },
                })
                .then((res) => {
                    this.labalertdata = res.data;
                    this.loading = false;
                })
                .catch((e) => {
                    this.$alert(e, "提示");
                    this.loading = false;
                });
        },
        //退出
        btnClose() {
            this.$emit("change", "close");
        },
        rowspanMethod({ row, $rowIndex, column, data }) {
            let fields = ["rptunitid", "sampledate", "sampleno"];
            let cellValue = row[column.property];
            if (cellValue && fields.includes(column.property)) {
                let prevRow = data[$rowIndex - 1];
                let nextRow = data[$rowIndex + 1];
                if (prevRow && prevRow[column.property] === cellValue) {
                    return { rowspan: 0, colspan: 0 };
                } else {
                    let countRowspan = 1;
                    while (nextRow && nextRow[column.property] === cellValue) {
                        nextRow = data[++countRowspan + $rowIndex];
                    }
                    if (countRowspan > 1) {
                        return { rowspan: countRowspan, colspan: 1 };
                    }
                }
            }
        },
    },
};
</Script>

<style scoped>
.remind_class {
    color: rgb(236, 11, 11);
    font-size: 18px;
}
::v-deep .mytable-style .vxe-body--row.row-pink {
    background-color: pink;
    color: rgb(8, 8, 8);
}
</style>
